package com.cdtye.shuoh.service.product.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdtye.shuoh.domain.product.entity.ProductTemplate;
import com.cdtye.shuoh.mapper.product.ProductTemplateMapper;
import com.cdtye.shuoh.service.product.ProductTemplateService;
import com.cdtye.shuoh.util.text.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductTemplateServiceImpl extends ServiceImpl<ProductTemplateMapper, ProductTemplate> implements ProductTemplateService {
    @Autowired
    private ProductTemplateMapper productTemplateMapper;

    @Override
    public void insertOrUpdateProductTemplate(ProductTemplate productTemplate) {
        if(null == productTemplate.getId()){
            productTemplate.setId(UUID.getUUID());
            productTemplateMapper.insertProductTemplate(productTemplate);
        }else{
            productTemplateMapper.updateProductTemplate(productTemplate);
        }
    }

    public String getTdengineJsonByProductIdAndServiceId(String productId,String serviceId){
       return productTemplateMapper.getTdengineJsonByProductIdAndServiceId(productId,serviceId);
    }

    public ProductTemplate getByProductIdAndServiceId(String productId,String serviceId){
        QueryWrapper<ProductTemplate> wrapper = new QueryWrapper<>();
        wrapper.eq("PRODUCT_ID",productId);
        wrapper.eq("SERVICE_ID",serviceId);
        return productTemplateMapper.selectOne(wrapper);
    }

    @Override
    public int deleteByProductIdentification(String productIdentification) {
        return productTemplateMapper.deleteByProductIdentification(productIdentification);
    }
}
